#include <cstdio>

using namespace std;

typedef long long ll;

const int maxs=5010, mods=998244353;

ll qpow(ll a, ll n) {
    ll s=1;
    for (; n; n/=2) {
        if (n&1) s=s*a%mods;
        a=a*a%mods;
    }
    return s;
}

ll solve1(int s, ll x) {
    ll ret=1;
    for (int i=0; i<=s+1; i++) {
        ret = ret*(x+s+1-i)%mods;
    }
    return ret*qpow(s+2, mods-2)%mods;
}

ll fact[maxs+4], invf[maxs+4], str[maxs+4][maxs+4], po[maxs+4][maxs+4], invv[4][maxs+4];

void initFact(int n) {
    fact[0] = 1;
    for (int i=1; i<=n; i++) fact[i] = fact[i-1]*i%mods;
    invf[n] = qpow(fact[n], mods-2);
    for (int i=n; i; i--) invf[i-1] = invf[i]*i%mods;
}

void initStr(int n) {
    str[0][0] = 1;
    for (int i=1; i<=n; i++) {
        for (int j=1; j<=i; j++) {
            str[i][j] = (str[i-1][j-1]+(i-1)*str[i-1][j]%mods)%mods;
        }
    }
}

void initPo(int n, int m) {
    for (int i=1; i<=m; i++) po[i][0] = 1;
    for (int i=1; i<=n; i++) {
        for (int j=1; j<=m; j++) po[j][i] = po[j][i-1]*j%mods;
    }
}

void initInvv(ll a[], int t, int n) {
    for (int i=1; i<=n; i++) {
        a[i] = qpow(t-i, mods-2);
    }
}

ll sum(int n, int m, ll *a) {
    ll ret=0;
    if (m<=n+2) {
        for (int i=1; i<=m; i++) {
            ret = (ret+po[i][n])%mods;
        }
    } else {
        ll t=1, sum=0;
        for (int i=1; i<=n+2; i++) {
            t = t*(m-i)%mods;
        }

        for (int i=1; i<=n+2; i++) {
            sum = (sum+po[i][n])%mods;
            ret = (ret+mods+sum*t%mods*a[i]%mods*invf[i-1]%mods*invf[n+2-i]%mods*((n+2-i)%2 ? -1 : 1))%mods;
        }
    }
    return ret;
}

ll bisum(int n, int m, int typ) {
    return (sum(n, m, invv[typ]) - po[2][n]*sum(n, m/2, invv[typ+1])%mods + mods)%mods;
}

ll solve2(int s, int x) {
    initInvv(invv[0], x+s, s+3);
    initInvv(invv[1], (x+s)/2, s+3);
    initInvv(invv[2], s, s);
    initInvv(invv[3], s/2, s/2);
    ll ret=0, fl = (s+1)%2 ? -1 : 1;
    for (int k=0; k<=s+1; k++, fl=-fl) {
        ret = (ret+mods+(bisum(k, x+s, 0)-bisum(k, s, 2)+mods)%mods*str[s+1][k]%mods*fl)%mods;
    }
    return ret;
}

int main() {
    freopen("pk.in", "r", stdin);
    freopen("pk.out", "w", stdout);

    int l, r, s, typ;
    scanf("%d %d %d %d", &l, &r, &s, &typ);
    if (typ==1) printf("%lld\n", (solve1(s, r)-solve1(s, l-1)+mods)%mods);
    else {
        initFact(s+3);
        initStr(s+3);
        initPo(s+3, s+3);
        printf("%lld\n", (solve2(s, r)-solve2(s, l-1)+mods)%mods);
    }

    fclose(stdin);
    fclose(stdout);
    return 0;
}
